import prefix from './prefix';

export default function mss_format(mss: number, fixed: 0 | 1 | 2 | 3, type: 0 | 1 | 2) {
	const _fixed = fixed === 0 ? 2 : fixed + 3;
	const days = mss > 86400000 ? parseInt((mss / (1000 * 60 * 60 * 24)).toString(), 10) : 0;
	const hours = parseInt(((mss % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)).toString(), 10);
	const minutes = parseInt(((mss % (1000 * 60 * 60)) / (1000 * 60)).toString(), 10);
	const seconds = (mss % (1000 * 60)) / 1000;
	const _days = days ? days + '天' : '';
	if (type === 0) {
		return _days + prefix(hours, 2) + ' 小时 ' + prefix(minutes, 2) + ' 分钟 ' + prefix(seconds.toFixed(fixed), _fixed) + ' 秒 ';
	} else if (type === 1) {
		return _days + prefix(hours, 2) + ':' + prefix(minutes, 2) + ':' + prefix(seconds.toFixed(fixed), _fixed);
	} else {
		// 超过100小时会有问题
		return prefix(days * 24 + hours, 2) + ':' + prefix(minutes, 2) + ':' + prefix(seconds.toFixed(fixed), _fixed);
	}
}
